/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aletex.da;

import aletex.entity.User;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author cibervn
 */
@Stateless
public class UserFacade extends AbstractFacade<User> {

    @PersistenceContext(unitName = "aletexPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UserFacade() {
        super(User.class);
    }

    public User findUserByUsername(String username) {
        Query query = getEntityManager().createNamedQuery("User.findByUsername", User.class);
        query.setParameter("username", username);
        try {
            return (User) query.getSingleResult();
        } catch (Exception e) {
            return null;
        }
    }
}
